package org.bedracket.bedracketenchantment.event;

import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.animal.Animal;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraftforge.event.entity.player.AttackEntityEvent;
import net.minecraftforge.eventbus.api.Event;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import org.bedracket.bedracketenchantment.BREMod;
import org.bedracket.bedracketenchantment.init.ModEnchantments;

@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE, modid = BREMod.MOD_ID)
public class PlayerEvents {

    @SubscribeEvent
    public void onPlayerAttack(AttackEntityEvent event) {
        if (EnchantmentHelper.getItemEnchantmentLevel(ModEnchantments.MERCY.get(), event.getPlayer().getMainHandItem()) > 0
                && event.getTarget() instanceof final Animal animal) {
            animal.addEffect(new MobEffectInstance(MobEffects.HEAL, 2 * 50));
        }
    }
}
